﻿import request from "@/utils/request";
import { useSettingsStore } from "@/store";
import { Regulation } from "@/types/business/regulation";

const settingStore = useSettingsStore();
const BASE_URL = `/api/${settingStore.elementRoutePrefix}/Regulation`;

const RegulationAPI = {
  // 获取所有规程
  getList(name?: string) {
    const formData = new FormData();
    formData.append("name", name ?? "");
    return request<any, Regulation[]>({
      url: `${BASE_URL}/GetListByName/`,
      method: "post",
      data: formData,
      headers: {
        "Content-Type": "multipart/form-data",
      },
    });
  },

  // 获取
  getOrDefault(id?: number) {
    return request<any, Regulation>({
      url: `${BASE_URL}/GetOrDefault/${id ?? ""}`,
      method: "post",
    });
  },

  // 删除
  delete(id: number) {
    return request<any, any>({
      url: `${BASE_URL}/Delete/${id}`,
      method: "post",
    });
  },

  // 添加或修改
  modifyDeviceConfig(item: Regulation) {
    return request<any, any>({
      url: `${BASE_URL}/AddOrUpdate`,
      method: "post",
      data: item,
    });
  },
};

export default RegulationAPI;
